package com.aspose.cells.a.d.a;

import com.aspose.cells.a.d.a.a.zap;
import com.aspose.cells.a.d.a.a.zau;
import com.aspose.cells.a.d.a.a.zba;
import com.aspose.cells.a.d.a.a.zbb;
import com.aspose.cells.a.d.a.a.zbl;
import com.aspose.cells.a.d.a.a.zbm;
import com.aspose.cells.a.d.a.a.zq;
import com.aspose.cells.a.d.a.b.zo;
import com.aspose.cells.a.d.a.b.zs;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;

public class zf {
   protected double a;
   protected double b;
   private zh c;
   private Rectangle d;
   private boolean e;
   private boolean f = false;
   private int g = 0;
   private Point[] h = new Point[4];
   private int i = 0;
   private float[] j;
   private float[] k;
   private byte[] l;
   private final zj m;
   private final boolean n;

   public zf(zj var1, zh var2, Rectangle var3) {
      this.m = var1;
      this.a = 0.0D;
      this.b = 0.0D;
      this.c = var2;
      this.d = var3;
      this.e = false;
      this.n = var1.e();
      if (this.n) {
         this.j = new float[8];
         this.k = new float[8];
         this.l = new byte[8];
      }

   }

   private void a(double var1, double var3) {
      this.a();
      this.a = var1;
      this.b = var3;
      var1 = (double)this.a(var1);
      var3 = (double)this.a(var3);
      if (this.n) {
         this.a(var1, var3, (byte)0);
      }

      this.c.a(new zau(new Point((int)var1, (int)var3)));
   }

   private void b(double var1, double var3) {
      if (this.g >= this.h.length) {
         Point[] var5 = new Point[this.g << 1];
         System.arraycopy(this.h, 0, var5, 0, this.g);
         this.h = var5;
      }

      var1 = (double)this.a(var1);
      var3 = (double)this.a(var3);
      int var7 = (int)var1;
      int var6 = (int)var3;
      if (this.f || var7 < -32768 || var7 > 32767 || var6 < -32768 || var6 > 32767) {
         this.f = true;
      }

      if (this.h[this.g] == null) {
         this.h[this.g] = new Point(var7, var6);
      } else {
         this.h[this.g].move(var7, var6);
      }

      if (this.n) {
         this.a(var1, var3, (byte)(this.e ? 3 : 1));
      }

      ++this.g;
   }

   private void a(double var1, double var3, byte var5) {
      if (this.i >= this.j.length) {
         float[] var6 = new float[this.i << 1];
         System.arraycopy(this.j, 0, var6, 0, this.i);
         this.j = var6;
         var6 = new float[this.j.length];
         System.arraycopy(this.k, 0, var6, 0, this.i);
         this.k = var6;
         byte[] var7 = new byte[this.j.length];
         System.arraycopy(this.l, 0, var7, 0, this.i);
         this.l = var7;
      }

      this.j[this.i] = (float)var1;
      this.k[this.i] = (float)var3;
      this.l[this.i] = var5;
      ++this.i;
   }

   private void c(double var1, double var3) {
      if (this.e && this.g > 0) {
         this.a();
      }

      this.e = false;
      this.b(var1, var3);
      this.a = var1;
      this.b = var3;
   }

   private void a(double var1, double var3, double var5, double var7, double var9, double var11) {
      if (!this.e && this.g > 0) {
         this.a();
      }

      this.e = true;
      this.b(var1, var3);
      this.b(var5, var7);
      this.b(var9, var11);
      this.a = var9;
      this.b = var11;
   }

   private void d(double var1, double var3) {
      this.a();
      if (this.n && this.i > 0) {
         this.l[this.i - 1] = (byte)(this.l[this.i - 1] | 128);
      }

      this.c.a(new zq());
      this.a = 0.0D;
      this.b = 0.0D;
   }

   private void a() {
      if (this.g > 0) {
         Object var1;
         if (this.e) {
            if (this.f) {
               var1 = new zba(this.d, this.g, this.h);
            } else {
               var1 = new zbb(this.d, this.g, this.h);
            }
         } else if (this.g == 1) {
            var1 = new zap(this.h[0]);
         } else if (this.f) {
            var1 = new zbl(this.d, this.g, this.h);
         } else {
            var1 = new zbm(this.d, this.g, this.h);
         }

         this.c.a((zg)var1);
      }

      this.g = 0;
      this.f = false;
      this.a = 0.0D;
      this.b = 0.0D;
   }

   public boolean a(Shape var1, int var2) {
      return this.a(var1, (AffineTransform)null, var2);
   }

   public boolean a(Shape var1, AffineTransform var2, int var3) {
      PathIterator var4 = var1.getPathIterator(var2);
      double[] var5 = new double[6];
      boolean var6 = true;
      double var7 = 0.0D;

      for(double var9 = 0.0D; !var4.isDone(); var4.next()) {
         int var11 = var4.currentSegment(var5);
         switch(var11) {
         case 0:
            this.a(var5[0], var5[1]);
            var7 = var5[0];
            var9 = var5[1];
            break;
         case 1:
            this.c(var5[0], var5[1]);
            break;
         case 2:
            this.a(var5[0], var5[1], var5[2], var5[3]);
            break;
         case 3:
            this.a(var5[0], var5[1], var5[2], var5[3], var5[4], var5[5]);
            break;
         case 4:
            this.d(var7, var9);
         }
      }

      this.a();
      if (this.n) {
         this.m.a((zs)(new zo(var3 - 1, this.j, this.k, this.l, this.i)));
      }

      this.i = 0;
      return var4.getWindingRule() == 0;
   }

   private void a(double var1, double var3, double var5, double var7) {
      double var9 = var1 + (this.a - var1) / 3.0D;
      double var11 = var3 + (this.b - var3) / 3.0D;
      double var13 = var1 + (var5 - var1) / 3.0D;
      double var15 = var3 + (var7 - var3) / 3.0D;
      this.a(var9, var11, var13, var15, var5, var7);
      this.a = var5;
      this.b = var7;
   }

   private float a(double var1) {
      return (float)(var1 * 1.0D * 20.0D);
   }

   public static boolean a(Shape var0) {
      return var0.getPathIterator((AffineTransform)null).getWindingRule() == 0;
   }
}
